//
//  ZBDBaseViewController.m
//  ZDB
//

//

#import "ZBDBaseViewController.h"
#import "ZDBAlertUtils.h"
@interface ZBDBaseViewController ()

@end

@implementation ZBDBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.modelsArry = [NSMutableArray array];
     self.view.backgroundColor = [UIColor colorWithHexString:@"#f8f8f8"];
    [self SetTheLoadProperties:YES];
    // 设置基类初始属性
    [self settingsViewControllerAttribute];
    [self axcBaseRequestData];
    
}
- (void)SetTheLoadProperties:(BOOL)enabled{
    if (enabled) {
        //禁用侧滑手势方法
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }else
    {
        //禁用侧滑手势方法
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}
- (void)viewDidAppear:(BOOL)animated
{
    [self stopLoadingAnimation];
}
- (void)showLoadingAnimation
{
    [[ZDBAlertUtils sharedZDBAlertUtils] show:kWindow];
}
- (void)stopLoadingAnimation
{
    [[ZDBAlertUtils sharedZDBAlertUtils] stopWait];
}
- (void)settingsViewControllerAttribute{
    // 将打印日志属性设置为默认NO
    //    _axcBasePrintLog = NO;
    //    self.page = 1;
    // 设置每个子类的背景颜色
   
    
    // 选择打印当前日志
    [self performSelector:@selector(printNSLog) withObject:nil afterDelay:1.0f];
    
}
- (void)printNSLog{
    if (_axcBasePrintLog) {
        printf("\n----------------=开始设置当前界面属性默认值=----------------\n");
        NSLog(@"BaseViewController:\n设置当前page值为：\t%d\n",_page);
        NSLog(@"BaseViewController:\n设置当前子类的背景颜色为：\t白色\n");
        NSLog(@"BaseViewController:\n设置当前子类的NavBar上的渲染颜色为：\t白色\n");
        NSLog(@"BaseViewController:\n设置当前的Tabbar风格为：\tUIBarStyleBlack\n");
        NSLog(@"BaseViewController:\n设置当前取消ScrollerView自适应属性：\tautomaticallyAdjustsScrollViewInsets = NO\n");
        NSLog(@"BaseViewController:\n设置当前tabbar选中的渲染颜色：\t红色：RGBA：220，9，64，1\n");
        printf("----------------=当前界面属性的默认值设置完毕=----------------\n\n");
    }
}
- (void)SetNavigationBarTitleColor:(UIColor *_Nonnull)color {
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:color}];
}

- (void)barLine:(BOOL)isLine
{
    if (isLine) {
       

    }else
    {
        
    }
}
- (void)SetnavigationBarBackgroundImage:(UIColor *)color Alpha:(NSInteger)Alpha;
{
    [self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[color colorWithAlphaComponent:Alpha]] forBarMetrics:UIBarMetricsDefault];
}
- (UIImage *)imageWithColor:(UIColor *)color
{
    // 描述矩形
    CGRect rect           = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    
    // 开启位图上下文
    UIGraphicsBeginImageContext(rect.size);
    // 获取位图上下文
    CGContextRef context  = UIGraphicsGetCurrentContext();
    // 使用color演示填充上下文
    CGContextSetFillColorWithColor(context, [color CGColor]);
    // 渲染上下文
    CGContextFillRect(context, rect);
    // 从上下文中获取图片
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    // 结束上下文
    UIGraphicsEndImageContext();
    return theImage;
}
- (void)statusBarStyleIsDark:(BOOL)statusBarStyleIsDark
{
    if (statusBarStyleIsDark)
    {
        if (@available(iOS 13.0, *)) {
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDarkContent];
        } else {
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
        }

    }else
    {
      
        if (@available(iOS 13.0, *)) {
            [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        } else {
            [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        }
        
    }
}
/**
 *  数据请求
 */
- (void)axcBaseRequestData{
}

/**
 *  添加右按钮
 *
 *  @param image 图片
 */
- (void)axcBaseAddRightBtnWithImage:(UIImage *)image{
    UIButton *baseRightImageButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 25, 25)];
    [baseRightImageButton setImage:image forState:UIControlStateNormal];
    [baseRightImageButton addTarget:self action:@selector(axcBaseClickBaseRightImageBtn:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:baseRightImageButton];
}
- (void)axcBaseClickBaseRightImageBtn:(UIButton *)sender
{
    
}
- (void)axcBaseClickBaseRightTitleStr:(NSString *)titleStr{
    
    UIButton *baseRightImageButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 25, 25)];
    [baseRightImageButton setTitle:titleStr forState:0];
    baseRightImageButton.titleLabel.font = AutoFont(12);
    [baseRightImageButton setTitleColor:MAINTITLECOLOR forState:0];
    [baseRightImageButton addTarget:self action:@selector(axcBaseClickBaseRightImageBtn:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:baseRightImageButton];
}
/**
 *  添加右按钮
 *
 *  @param type 系统风格
 */
- (void)axcBaseAddRightBtnWithType:(UIBarButtonSystemItem)type{
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:type target:self action:@selector(axcBaseClickBaseRightTypeBtn:)];
}
- (void)axcBaseClickBaseRightTypeBtn:(UIBarButtonItem *)sender{
}

- (void)axcBaseAddTitleLableWithTitle:(NSString *)title{
    
}
/**
 *   下拉刷新
 */
- (void)axcBaseLoadNewData{
    _page = 1;
    [self axcBaseRequestData];
    
}

/**
 *  上拉加载
 */
- (void)axcBaseLoadMoreData{
    _page ++;
    [self axcBaseRequestData];
   
}
/**
 *  返回方法
 *
 */
- (void)handleNavigationTransition:(UIPanGestureRecognizer *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)initBackButton:(BOOL)left {
    if(left){
        UIButton * backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        backButton.frame = CGRectMake(0, 0, 50, 40);
        [backButton setImage:[UIImage imageNamed:@"K_goback"] forState:UIControlStateNormal];
        [backButton addTarget:self action:@selector(didBack) forControlEvents:UIControlEventTouchUpInside];
        backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    }else{
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
                                                 initWithTitle:@""
                                                 style:UIBarButtonItemStylePlain
                                                 target:nil
                                                 action:nil];
    }
}
- (void)didBack{
    [self.navigationController popViewControllerAnimated:YES];
}
@end
